<?php
namespace App\Api\Controllers;

use App\Api\Models\Goods;
use App\Http\Controllers\Controller;
use App\Api\Services\JsonService;
use App\Api\Models\GoodsCategory;
use Illuminate\Http\Request;

class CategorypageController extends Controller
{
    /**
     * 分类页面展示
     * @param int $pid 顶级id 0
     * @return array
     */
    public function getCategoryPage()
    {
        $CaData = GoodsCategory::getCategoryData();

        if($CaData){
            return JsonService::success($CaData);
        }
        return JsonService::fail('查询数据为空');
    }

    public function getPageValue(Request $request)
    {
        $validate = $request->validate(['category_id'=>['required']]);

        $allowField = [
            'goods_id',
            'goods_name',
            'goods_state',
            'cate_id',
            'goods_image',
            'price',
            'introduction',
            'sale_num'
        ];

        $PageData = Goods::getPageData($validate['category_id'],$allowField);

        if($PageData){
            return JsonService::success($PageData);
        }
        return JsonService::fail('查询数据为空');
    }
}
